package com.baizhiedu.baizhiappsys.dao.impl;

import com.baizhiedu.baizhiappsys.dao.PayDao;
import com.baizhiedu.baizhiappsys.entity.Pay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author lby
 */
@Repository
public class PayDaoImpl implements PayDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void insertPay(Pay pay) {
        String sql = "insert into t_pay(user_id,pay_device,pay_course_id,pay_time,pay_method,pay_device_ip_address) value(?,?,?,?,?,?)";

        int update = jdbcTemplate.update(sql, pay.getUserId(), pay.getPayDevice(), pay.getPayCourseId(), pay.getPayTime(), pay.getPayMethod(), pay.getPayDeviceIpAddress());

        System.out.println(update);
    }

    @Override
    public Integer selectPayCountByPayMethod(String payMethod) {
        String sql = "SELECT COUNT(*) FROM t_pay WHERE pay_method = ?";
        Integer integer = jdbcTemplate.queryForObject(sql, Integer.class,payMethod);
        return integer;
    }
}
